package com.ftg.learn.service.impl;

import com.ftg.learn.dto.AddProductDto;
import com.ftg.learn.mapper.ShopProductMapper;
import com.ftg.learn.service.ShopProductService;
import com.ftg.learn.util.PageEx;
import com.ftg.learn.util.R;
import com.ftg.learn.vo.ProductListVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 布衣
 */
@Service
public class ShopProductServiceImpl implements ShopProductService {

    @Resource
    private ShopProductMapper shopProductMapper;

    /**
     * 调用mapper查询 全部商品信息
     */
    @Override
    public R<PageEx<ProductListVo>> listForAll(String categoryName, String productName, Integer pageNum, Integer pageSize) {
        PageEx<ProductListVo> pageex = new PageEx<>();
        pageex.setPageNum(pageNum);
        pageex.setPageSize(pageSize);
        Integer start = (pageNum - 1) * pageSize;
        pageex.setTotal(shopProductMapper.totalList(categoryName,productName));
        pageex.setData(shopProductMapper.productList(categoryName, productName,start , pageSize));

        return R.ok(pageex);
    }

    @Override
    public R<Integer> saveProduct(AddProductDto dto) {
        return R.ok(shopProductMapper.saveProduct(dto));
    }

    //CRUD
}
